/**
ysbEePatch.mg
*/


class AppDelegate:UIResponder {

- (void)openProtectionsAction {
    self.openAvoidCrashAction();

}

- (void)closeWebSocket {
    YSBWebSocketManager.shared().webSocketClose();
    YSBChatRoomWebSocketManager.shared().webSocketClose();
}


- (void)openWebSocket {
    if (YSBUserDefaultsTool.boolForKey:(@"kIsLoginSuccess")) {
        YSBWebSocketManager.shared().webSocketClose();
        YSBWebSocketManager.shared().connectServer();
        
        YSBChatRoomWebSocketManager.shared().webSocketClose();
        YSBChatRoomWebSocketManager.shared().connectServer();
    }
    
}


- (void)faceStart {
    self.locationManager.startUpdatingLocation();
    
}


- (void)faceStop {
    self.locationManager.stopUpdatingLocation();
    
}


}



class YSBHomeController:YSBViewController {

- (void)judgeShowOrHidePopViewWithModel:(YSBSystemConfigModel *)configModel {

    if (configModel.recommendedModel.startTime.length > 0 && configModel.recommendedModel.endTime.length > 0) {
    
        NSString *startTimeStr = configModel.recommendedModel.startTime;
        NSString *endTimeStr = configModel.recommendedModel.endTime;
        
        NSMutableString *mutStr = NSMutableString.alloc().initWithString:(@"每日优选于每日 \n");
        mutStr.appendString:(startTimeStr);
        mutStr.appendString:(@"~");
        mutStr.appendString:(endTimeStr);
        mutStr.appendString:(@"开启");
    
        self.popLabel.text = mutStr;
    }
    
   self.performSelector:withObject:afterDelay:(@selector(delayMethod),nil,1.2);
   self.performSelector:withObject:afterDelay:(@selector(delayMethod),nil,2.2);
   self.performSelector:withObject:afterDelay:(@selector(delayMethod),nil,3.2);
   self.performSelector:withObject:afterDelay:(@selector(delayMethod),nil,4.2);
   self.performSelector:withObject:afterDelay:(@selector(delayMethod),nil,6.2);
}

- (void)delayMethod {
    self.dealWithShowOrHidePop();
    YSBMSAlertManager.shareManager().showAlerts();
}


- (void)viewDidAppear:(BOOL)animated {
    super.viewDidAppear:(animated);
    YSBMSAlertManager.shareManager().showAlerts();
}


- (void)changeOrderStatus:(NSNotification *)no {
    
    if (no.name.isEqualToString:(@"comeFromHomeChangeOrderStatusNotification")) {//来自首页
        self.take_type = @"normal";
    }else if (no.name.isEqualToString:(@"comeFromCollectionChangeOrderStatusNotification")) {//来自收藏
        self.take_type = @"collect";
    }else if (no.name.isEqualToString:(@"comeFromAcceptableChangeOrderStatusNotification")) {//来自可接订单
        self.take_type = @"myboss";
    }else if (no.name.isEqualToString:(@"comeFromInvitationChangeOrderStatusNotification")) {//来自人才库邀请
        self.take_type = @"invite";
    }else if (no.name.isEqualToString:(@"comeFromGoodOrderOfHomeNotification")) {//来自每日优选首页入口
        self.take_type = @"hpush";
    }else if (no.name.isEqualToString:(@"comeFromGoodOrderOfMessageNotification")) {//来自每日优选消息入口
        self.take_type = @"mpush";
    }else if (no.name.isEqualToString:(@"comeFromShareNotification")) {//来自分享入口
        self.take_type = @"share";
    }else if (no.name.isEqualToString:(@"comeFromMessageChangeOrderStatusNotification")) {//来自通知或消息列表进入详情
        self.take_type = @"mpush";
    }
    
    if (YSBCommonTool.isBlankString:(self.take_type)) {
        self.take_type = @"normal";
    }
    
    
    if (!YSBCommonTool.isBlankString:(no.userInfo[@"oid"])) {
        NSString *oidStr = no.userInfo[@"oid"];
        self.oid = oidStr;
    }
    
    if (no.object.isKindOfClass:(YSBChildOrdelDetailModel.class())) {
        YSBChildOrdelDetailModel *ordelDetailModel = no.object;
        self.ordelDetailModel = ordelDetailModel;
        if (!YSBCommonTool.isBlankString:(ordelDetailModel.time_type)) {
            self.timeType = ordelDetailModel.time_type;
        }
    }

    
    NSString *event = no.userInfo[@"event"];
    
    self.isNoticeEvent = YES;

    if (event.isEqualToString:(@"go")) {//立即抢单
        self.goAction();
        
    }
    if (event.isEqualToString:(@"next")) {//下一个
        self.changeAction();
    }
    if (event.isEqualToString:(@"cancel")) {//取消匹配
        self.cancelAction();
    }
    
    
}



}



class YSBMineController : YSBViewController {


- (void)viewDidAppear:(BOOL)animated {
    super.viewDidAppear:(animated);
    YSBMSAlertManager.shareManager().showAlerts();
}


}



class YSBGoodOrderViewController:YSBViewController {

- (void)judgeHideOrShowChatRoom:(BOOL)isShowChatRoom {
    
    BOOL isHidden = !isShowChatRoom;
    
    self.chatRoomView.hidden = isHidden;
    self.inputController.view.hidden = isHidden;
    self.topImgView.hidden = isHidden;
    
    self.barrageManager.renderView.hidden = isHidden;
    self.barrageBtn.hidden = isHidden;
    
    self.originalChatRoomHidden = isHidden;

}


- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
    if (gestureRecognizer == self.navigationController.interactivePopGestureRecognizer) {
        if (self.navigationController.viewControllers.count <= 2 || self.navigationController.visibleViewController == self.navigationController.viewControllers.objectAtIndex:(0)) {
            return NO;
        }
    }
    return YES;
}


}



class YSBChildOrderDetailViewController:YSBViewController {

- (void)shareOrderWithTitle:(NSString *)title andDesc:(NSString *)desc andUrlStr:(NSString *)shareUrl {

    NSString *uid = @"";
    
    NSURL *url = YSBChatRoomWebSocketManager.shared().webScoket.url;
    NSString *urlStr = url.absoluteString();
    NSString *sepKey = @"uid=";
    if (urlStr.containsString:(sepKey)) {
        NSArray *arr = urlStr.componentsSeparatedByString:(sepKey);
        if (arr.count > 1) {
            uid = arr[1];
        }
    }
    NSString *tempStr = shareUrl.stringByAppendingString:(@"&share_uid=");
    NSString *shareAllUrl = tempStr.stringByAppendingString:(uid);

    self.goToShareActionWithTitle:andDesc:andUrlStr:(title,desc,shareAllUrl);
    
}



}



class YSBPunchCardDetailViewController:YSBViewController {

- (void)showGoOnOrderTipsWithPuchInfoModel:(YSBPunchInfoModel *)puchInfoModel andPunchCardInfoModel:(YSBPunchCardInfoModel *)model {

    if (self.isNextTask) {
        YSBNextTaskModel *nextTaskModel = puchInfoModel.nextTaskModel;
        NSString *startWorkTime = nextTaskModel.start_work_time;
        
        startWorkTime = YSBCommonTool.isBlankString:(startWorkTime) ? @"" : startWorkTime;
        
        NSMutableString *mutStr = NSMutableString.alloc().initWithString:(@"恭喜您完成今天的工作，明天上班时间为： \n");
        mutStr.appendString:(startWorkTime);
        mutStr.appendString:(@"请准时打卡上班。");
        
        NSString *message = mutStr;
        YSBCommonTool.showSigleBtnAlertViewControllerWithTitle:andMessage:andBtnTitle:andBtnAction:(@"温馨提示",message,@"知道了",^UIAlertAction *(UIAlertAction *action) {});
    }
}


}



class YSBMainADScrollView : UIView {

- (UIButton *)leftBtn {
    if (!_leftBtn) {
        _leftBtn = UIButton.alloc().init();
        _leftBtn.setBackgroundImage:forState:(YSBCommonTool.autoreleasepoolWithImageName:(@"adBox_left"),UIControlStateNormal);
        _leftBtn.addTarget:action:forControlEvents:(self,@selector(leftBtnAction:),UIControlEventTouchUpInside);
        _leftBtn.hidden = self.dataSourse.count < 2 ? YES : NO;
    }
    return _leftBtn;
}

- (UIButton *)rightBtn{
    if (!_rightBtn) {
        _rightBtn = UIButton.alloc().init();
        _rightBtn.setBackgroundImage:forState:(YSBCommonTool.autoreleasepoolWithImageName:(@"adBox_left"),UIControlStateNormal);
        _rightBtn.addTarget:action:forControlEvents:(self,@selector(rightBtnAction:),UIControlEventTouchUpInside);
        _rightBtn.hidden = self.dataSourse.count < 2 ? YES : NO;
    }
    return _rightBtn;
}


}



class YSBAccountStatusViewController : YSBViewController {


- (void)noticeStatus:(NSNotification *)no {
    
    if (no.name.isEqualToString:(@"comeFromHomeChangeOrderStatusNotification")) {//来自首页
        self.take_type = @"normal";
    }else if (no.name.isEqualToString:(@"comeFromCollectionChangeOrderStatusNotification")) {//来自收藏
        self.take_type = @"collect";
    }else if (no.name.isEqualToString:(@"comeFromAcceptableChangeOrderStatusNotification")) {//来自可接订单
        self.take_type = @"myboss";
    }else if (no.name.isEqualToString:(@"comeFromInvitationChangeOrderStatusNotification")) {//来自人才库邀请
        self.take_type = @"invite";
    }else if (no.name.isEqualToString:(@"comeFromGoodOrderOfHomeNotification")) {//来自每日优选首页入口
        self.take_type = @"hpush";
    }else if (no.name.isEqualToString:(@"comeFromGoodOrderOfMessageNotification")) {//来自每日优选消息入口
        self.take_type = @"mpush";
    }else if (no.name.isEqualToString:(@"comeFromShareNotification")) {//来自分享入口
        self.take_type = @"share";
    }else if (no.name.isEqualToString:(@"comeFromMessageChangeOrderStatusNotification")) {//来自通知或消息列表进入详情
        self.take_type = @"mpush";
    }
    
    if (YSBCommonTool.isBlankString:(self.take_type)) {
        self.take_type = @"normal";
    }
    
    
    if (!YSBCommonTool.isBlankString:(no.userInfo[@"oid"])) {
        NSString *oidStr = no.userInfo[@"oid"];
        self.oid = oidStr;
    }
    
    if (no.object.isKindOfClass:(YSBChildOrdelDetailModel.class())) {
        YSBChildOrdelDetailModel *ordelDetailModel = no.object;
        self.ordelDetailModel = ordelDetailModel;
        if (!YSBCommonTool.isBlankString:(ordelDetailModel.time_type)) {
            self.timeType = ordelDetailModel.time_type;
        }
    }

    
    NSString *event = no.userInfo[@"event"];
    
    self.isNoticeEvent = YES;

    if (event.isEqualToString:(@"go")) {//立即抢单
        self.goAction();
        
    }
    if (event.isEqualToString:(@"next")) {//下一个
        self.changeAction();
    }
    if (event.isEqualToString:(@"cancel")) {//取消匹配
        self.cancelAction();
    }
    
}


}



class YSBChildOrderDetailComplaintViewController : YSBViewController {


- (void)viewDidAppear:(BOOL)animated {
    super.viewDidAppear:(animated);
    self.orderMoneyTitleTextField.textField.keyboardType = UIKeyboardTypeDecimalPad;
    
}


}
